/*
 * Copyright 2010-2011 WebEqua Team
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.mathcloud.math.core.matlab.operator.algebra;


import org.mathcloud.math.core.matlab.factory.MatlabQuantityObjectFactory;
import org.mathcloud.math.core.matlab.operator.MatlabBinaryOperator;
import org.mathcloud.math.core.matlab.quantity.MatlabQuantityObject;
import org.mathcloud.math.core.matlab.quantity.MatlabRealNumber;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.webequa.core.common.operator.algebra.Log;
import org.webequa.core.common.quantity.QuantityObject;
import org.webequa.core.common.signature.QuantityObjectSignature;

public class MatlabLog extends MatlabBinaryOperator implements Log
{
	public MatlabLog()
	{
		super();
		signature.setMMLContentTag("log");
	}

	@Override
	public void calculate()
	{
		if (getResultSignature()!=null)
		{
			if(operand2==null) {
				log.debug("Change operand 2, new value is 10");
				operand2 = new MatlabRealNumber(10);
			}
			
			MatlabQuantityObject tOp1 = MatlabQuantityObjectFactory.getInstance(operand1);
			MatlabQuantityObject tOp2 = MatlabQuantityObjectFactory.getInstance(operand2);

			MatlabLn Ln1 = new MatlabLn();
			MatlabLn Ln2 = new MatlabLn();
			MatlabDivide D = new MatlabDivide();
			Ln1.setInputParams(tOp1);
			Ln2.setInputParams(tOp2);
				
			Ln1.calculate();
			Ln2.calculate();
				
			QuantityObject Dn1 = Ln1.getResult();
			QuantityObject Dn2 = Ln2.getResult();
				
			D.setInputParams(Dn1, Dn2);
			D.calculate();
			res = D.getResult();
		}
		else {
			
			log.warn("ResultSignature isn't defined");
		}
	}	
	
	@Override
	public QuantityObjectSignature getResultSignature()
	{
    if (operand1!=null)
    {
    	return operand1.getSignature();
    } 
    return null;
	}

	
	private static final Logger log = LoggerFactory.getLogger(MatlabLog.class);

}
